package com.demo.mapper;

import com.demo.dto.OrderDTO;
import com.demo.entity.Carousel;
import com.demo.entity.Order;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.List;

@Repository
public interface OrderMapper {

    @Select("select DISTINCT orders.order_id ,u.userName ,\n" +
            "date_format(FROM_UNIXTIME(order_time /1000),'%Y-%m-%d %H:%i:%s') order_time from orders\n" +
            "inner join users u on u.user_id =orders.user_id order by order_time desc")
    List<OrderDTO> findAllOrders();

    @Select("select SUM(product_price)  from orders\n" +
            " where order_id=#{orderId}")
    double findSumPriceByOrderId(BigDecimal orderId);

    @Select("select orders.id ,p.product_name,orders.product_num ,p.product_picture ,orders.product_price ,\n" +
            "date_format(FROM_UNIXTIME(order_time /1000),'%Y-%m-%d %H:%i:%s') order_time from orders\n" +
            "inner join product p on p.product_id =orders.product_id  where order_id=#{orderId}")
    List<Order> findOrdersById(BigDecimal orderId);
}
